#include "../inc/my_picture.h"
#include "../inc/touch.h"
#include "../inc/bmp.h"
#include "../inc/dir.h"
#include "../inc/test.h"
#include "../inc/lcd.h"
#include "../inc/saveBmp.h"

//相册界面展示
void picture_show(){
    //展示相册背景图片
    bmp_show("./res/interface/picture_background.bmp",0,0);
}

//相册点击操作
void picture_background_touch(char* user){
    //创建一个二维数组存储所有文件名
    char cloth_name[10][30];
    int flag = 0;
    DIR* dir;
    struct dirent* ent;
    if((dir = opendir("./res/cloth")) == NULL){//打开cloth目录
        perror("opendir() error");
        return;
    }
    //读取目录中每一个文件
    while((ent = readdir(dir)) != NULL){
        // 忽略 '.' 和 '..'  
        if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {  
            continue;  
        }  
        //printf("%s\n",ent->d_name);//打印文件名
        sprintf(cloth_name[flag], "./res/cloth/%s", ent->d_name);
        //printf("%s\n",cloth_name[flag]);
        flag++;
    }
    closedir(dir);//关闭目录

    //printf("%s\n",cloth_name[0]);

    // char* p1 = cloth_name[(flag--)%6];
    // printf("%s\n",p1);
    // char* p2 = cloth_name[(flag--)%6];
    // printf("%s\n",p2);
    // bmp_show(p1,180,160);
    // bmp_show(p2,440,160);

    // //先从文件里读取两个.bmp文件出来
    bmp_show_small(cloth_name[flag%6],180,160);
    bmp_show_small(cloth_name[(flag+1)%6],440,160);
    //滑动操作
    while(1)
    {
        switch (touch_wait_slide())
        {
        case 0:
            printf("left\n");
            bmp_show("./res/interface/picture_background.bmp",0,0);
            flag = (flag+5)%6;
            bmp_show_small(cloth_name[flag],180,160);  
            //main_font_library(0,0,"罗智");
            //printf("%d\n",flag);
            flag = (flag+5)%6;
            bmp_show_small(cloth_name[flag],440,160);
            //printf("%d\n",flag);
            break;
        case 1:
            bmp_show("./res/interface/picture_background.bmp",0,0);
            bmp_show_small(cloth_name[(flag++)%6],180,160);
            bmp_show_small(cloth_name[(flag++)%6],440,160);
            printf("right\n");
            break;
        case 2:
            printf("up\n");
            saveBMP(user, 800, 480);
            bmp_show_small("./res/interface/save1.bmp",0,0);
            usleep(200000);
            bmp_show_small("./res/interface/save2.bmp",0,0);
            usleep(200000);
            bmp_show_small("./res/interface/save3.bmp",0,0);
            usleep(200000);
            bmp_show_small("./res/interface/save4.bmp",0,0);
            usleep(200000);
            bmp_show("./res/interface/white_small.bmp",74,18);
            break;
        case 3:
            printf("down\n");
            //展示相册返回主界面
            bmp_show("./res/interface/picture_to_main.bmp",0,0);
            bmp_show_small("./res/interface/logo.bmp",0,0);
            time_prograss_bar();
            return;
        }
    }
}



